package cn.hpclub.server.controller.admin;/**
 * Created by zenghl on 2016/8/23.
 */

import cn.hpclub.server.model.CmccCardOrder;
import cn.hpclub.server.model.campus.BroadbandOpenOrder;
import cn.hpclub.server.service.CmccCardOrderService;
import cn.hpclub.server.service.campus.BroadbandOpenOrderService;
import cn.hpclub.server.util.ExcelRenderUtil;
import cn.hpclub.server.util.InterfaceUtil;
import cn.hpclub.server.util.ObjectUtil;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @FileName CmccCardOrderController
 * @Author zhl
 * @Description
 * @Date 2016-08-23 11:59
 * @CopyRight ZTE Corporation
 */
public class CmccCardOrderController extends BaseAdminController<CmccCardOrder> {

    private static Logger logger = LoggerFactory.getLogger(CmccCardOrderController.class);

    public void list(){
        ConcurrentHashMap<String, String> searchInfo = getSearchInfo();
        List<Record> list = InterfaceUtil.getAllCity();
        setAttr("city_list", list);// 加载地市列表
        int city_id = Integer.parseInt(getPara("group_id", "-1"));
        if(city_id == -1){
            int org_id = InterfaceUtil.getOrgId();
            Record record = InterfaceUtil.getInfoByOrg(org_id);
            if(ObjectUtil.isNotEmpty(record) && ObjectUtil.isNotEmpty(record.getInt("group_id"))){
                city_id = record.getInt("group_id");
            }
        }
        if((!searchInfo.contains("group_id") || "-1".equals(searchInfo.get("group_id"))) && city_id != -1){
            searchInfo.put("group_id", String.valueOf(city_id));
        }
        if("-1".equals(searchInfo.get("group_id"))){
            searchInfo.remove("group_id");
        }
        int city_id_attr = city_id;
        if(StrKit.notBlank(searchInfo.get("group_id"))){
            city_id_attr = Integer.parseInt(searchInfo.get("group_id"));
        }
        setAttr("group_id", city_id_attr);
        findByPageForSearch(new CmccCardOrderService().service.getSqlHead(),
                new CmccCardOrderService().service.getSqlExceptSelect(searchInfo));
        render("/admin/cmcc_card_order.tpl");
    }

    public void exportAll(){
        ConcurrentHashMap<String, String> searchInfo = getSearchInfo();
        if("-1".equals(searchInfo.get("city_id"))){
            searchInfo.remove("city_id");
        }
        SXSSFWorkbook workbook = new CmccCardOrderService().service.getExcel(searchInfo);
        render(new ExcelRenderUtil(workbook, "broadband_open_order"));
    }

}
